// pages/resume/uploadResume/uploadResume.js
import WeCropper from '../../../we-cropper/we-cropper.js';
const util = require('../../../utils/public_func.js');

const device = wx.getSystemInfoSync()
const width = device.windowWidth
const height = device.windowHeight

const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 基本参数
    type_id: [], //职位id
    type_name: '', //职位类型
    salaryRange_text: "0", //薪资范围

    focus: false,
    //期望底薪
    multiArray: [],
    multiIndex: [0, 0],
    pay_high: '0',
    pay_low: '0',

    stature_array: [], //身高
    weight_array: [], //体重
    live_age_array: [], //直播时长

    is_open: 1,




    //路径
    one_url: '',
    two_url: '',
    three_url: '',

    imageOne: '',
    imageTwo: '',
    imageThree: '',


    //base64
    one_base64: '',
    two_base64: '',
    three_base64: '',
    //基本信息
    name_value: '',
    phone_value: wx.getStorageSync('reg_telephone'),
    age: '',
    sex: null,
    girl: false,
    man: false,
    resume_id: '',
    date: '',

    is_resume: '',
    bianji_flag: 0,
    reg_true: false,
    welfare: false,

    // 裁剪图片
    cropperOpt: {
      id: 'cropper',
      width,
      height,
      scale: 2.5,
      zoom: 8,
      cut: {
        x: (width - 270) / 2,
        y: (height - 480) / 2,
        width: 270,
        height: 480
      }
    },
    tailor_show: true,
    //card 
    card_show: null,
    detail: '',


    type_flag: true,
    platform_flag: true,
    recuitStatus_flag: true,
    upload_fail: true,
    upload_ok: true,
    upload_go: true,
  },
  go_first_recruit() {
    this.setData({
      upload_go: true,
    })
    wx.redirectTo({
      url: '../../recruit/index/index?flag_first=true'
    })
  },
  //清除照片
  click_clear(e) {
    // console.log(e);
    let that = this,
      num = e.currentTarget.dataset.num;
    if (num == "1") {
      //第一张
      that.setData({
        one_url: '',
        // imageOne: '',
        one_base64: '',
      })
    } else if (num == "2") {
      //第二张  
      that.setData({
        two_url: '',
        // imageTwo: '',
        two_base64: '',
      })
    } else if (num == "3") {
      //第三张   
      that.setData({
        three_url: '',
        // imageThree: '',
        three_base64: '',
      })
    }
  },
  //获取焦点
  get_focus() {
    this.setData({
      focus: true,
    })
  },
  //点击底薪
  click_dixin() {
    this.setData({
      pay_high: "2000",
      pay_low: "1000",
    })
  },
  //简历是否隐藏
  open_sure(e) {
    let that = this;
    console.log(e.currentTarget.dataset.status);
    let status = e.currentTarget.dataset.status;
    if (status == "1") {
      //选择 是
      that.setData({
        is_open: 1,
      })
    } else {
      //选择 否
      that.setData({
        is_open: 2,
      })
    }
  },
  //个人优势
  inp_advantage(e) {
    console.log(e.detail.value)
    let per_style = e.detail.value;
    this.setData({
      per_style: per_style,
    })
  },
  //直播时长
  live_age_bindPicker(e) {
    let that = this;
    let index = parseFloat(e.detail.value);
    let items = this.data.live_age_array;
    let live_age = (items[index]).toString();
    console.log('picker发送选择改变，携带值为', items[index])
    this.setData({
      live_age: live_age,
    })
  },
  //体重
  weight_bindPicker(e) {
    let that = this;
    let index = parseFloat(e.detail.value);
    // let index = parseFloat(e.detail.value) + 1;
    let items = this.data.weight_array;
    console.log('picker发送选择改变，携带值为', items[index])
    this.setData({
      weight: items[index],
    })
  },
  //身高
  stature_bindPicker(e) {
    let that = this;
    let index = parseFloat(e.detail.value);
    // let index = parseFloat(e.detail.value) + 1;
    let items = this.data.stature_array;
    console.log('picker发送选择改变，携带值为', items[index])
    this.setData({
      stature: items[index]
    })
  },


  //底薪 滚轮动作
  bindMultiPickerColumnChange: function(e) {
    let that = this;
    console.log('修改的列为', e.detail.column, '，值为', e.detail.value);
    var multiArray = this.data.multiArray;
    var multiIndex = this.data.multiIndex;

    multiIndex[e.detail.column] = e.detail.value;

    var multiArray = this.data.multiArray;
    var multiIndex = this.data.multiIndex;
    var column = e.detail.column;
    var value = e.detail.value;
    console.log(value)
    switch (column) {
      case 0:
        var _low = multiArray[0][value];
        var pay_low = _low.replace("k", "000");
        // console.log(_low)
        this.setData({
          pay_low: pay_low
        })
        break;
      case 1:
        var _high = multiArray[1][value];
        var pay_high = _high.replace("k", "000");
        this.setData({
          pay_high: pay_high
        })
        break;
      default:
        console.log("null")
    }
    this.setData({
      multiArray: multiArray,
      multiIndex: multiIndex,
    });
  },
  go_refuse() {
    this.setData({
      upload_fail: true,
      upload_go: false,
    })
  },
  //薪资 确定
  bindMultiPickerChange() {
    console.log("点击确认")
    let high_old = this.data.pay_high.toString();
    let pay_high = high_old.replace("k", "000");
    let low_old = this.data.pay_low.toString();
    let pay_low = low_old.replace("k", "000");

    // console.log("pay_low+" + pay_low)
    // console.log("pay_high+"+pay_high)

    if (parseInt(pay_low) > parseInt(pay_high)) {
      // console.log("请重新输入");
      console.log("pay_low+" + pay_low)
      console.log("pay_high+" + pay_high)

      wx.showToast({
        title: '薪资范围错误',
        icon: "none"
      })
      this.setData({
        salaryRange_text: '',
      })
    } else {
      console.log("正常")
      this.setData({
        salaryRange_text: pay_low + "-" + pay_high,
      })
    }
    console.log(this.data.salaryRange_text);
  },
  //设置 直播年限
  get_live_age() {
    let arr = [];
    for (var i = 0; i <= 10; i++) {
      arr.push(i)
    }
    this.setData({
      live_age_array: arr
    })
  },
  //设置 体重
  get_weight() {
    let arr = [];
    for (var i = 30; i <= 120; i++) {
      // arr.push(i + "kg")
      arr.push(i)
    }
    this.setData({
      weight_array: arr
    })
  },
  //设置 身高
  get_stature() {
    let arr = [];
    for (var i = 50; i <= 220; i++) {
      arr.push(i)
    }
    this.setData({
      stature_array: arr
    })
  },
  //设置 K数
  get_salary() {
    let arr1 = [];
    let arr2 = [];

    for (var i = 1; i <= 49; i++) {
      arr1.push(i + "k")
    }
    for (var i = 2; i <= 50; i++) {
      arr2.push(i + "k")
    }
    let arr = [];
    arr.push(arr1)
    arr.push(arr2)
    this.setData({
      multiArray: arr
    })
  },
  only_recuitStatus(e) {
    // console.log(e);
    var index = e.currentTarget.dataset.recuitstatusindex; //获取当前点击的下标    
    var status_name = e.currentTarget.dataset.status_name;
    var wanted_status = e.currentTarget.dataset.id;
    var recuitStatus = this.data.recuitStatus; //选项集合    
    // console.log(index)
    if (recuitStatus[index].checked) return; //如果点击的当前已选中则返回    
    recuitStatus.forEach(item => {
      item.checked = false
    })
    recuitStatus[index].checked = true; //改变当前选中的checked值    
    this.setData({
      recuitStatus: recuitStatus,
      status_name: status_name,
      wanted_status: wanted_status,
    })
    this.modal_hide();
  },

  //点击主播类型
  only_recuitType(e) {
    let that = this;
    // console.log(this.data.type_name)
    var _type_id = e.currentTarget.dataset.id;
    var typeId = this.data.type_id;
    // console.log(typeId[0])
    if (that.data.type_id.length >= 3 && _type_id != typeId['0'] && _type_id != typeId[1] && _type_id != typeId[2]) {
      wx.showToast({
        title: '最多选三个',
        icon: 'none',
      })
    } else {
      console.log(e);
      var index = e.currentTarget.dataset.recuittypeindex; //获取当前点击的下标
      var _type_name = e.currentTarget.dataset.type_name;
      var _type_id = e.currentTarget.dataset.id;
      var recuitType = this.data.recuitType; //选项集合

      var type_name = this.data.type_name;
      var typeId = this.data.type_id;
      console.log("333+" + typeId)
      if (typeof(typeId) == "string") {
        var type_id = typeId.split(",");
        // console.log("11111111122222+" + type_id)
      } else {
        var type_id = typeId;
        console.log(22222222)

      }


      //平台文字
      if (type_name == "") {
        type_name = this.data.type_name + _type_name;
        // console.log(1)
      } else {
        if (type_name.indexOf(_type_name) == "-1") {
          type_name = type_name + ',' + _type_name;
          // console.log(2)
        } else {
          if (type_name.split(",").length > 1) {
            // console.log(type_name.length);
            type_name = type_name.replace(_type_name + ',', "");
            type_name = type_name.replace(',' + _type_name, "");
          } else {
            type_name = type_name.replace(_type_name, "");
          }
        }
      }
      //平台数字
      if (type_id == "") {
        type_id.push(_type_id);
        console.log("type_id1111+" + type_id)
        // console.log(1)
      } else {
        if (that.indexOf(type_id, _type_id) == "-1") {
          type_id.push(_type_id);
          // console.log(2)
        } else {
          that.remove(type_id, _type_id);
          // console.log(4)
        }
      }

      this.setData({
        type_name: '',
        type_id: '',

      })
      this.setData({
        type_name: type_name,
        type_id: type_id,
      })

      //选中状态
      // console.log(platfrom)
      if (recuitType[index].checked) {
        recuitType[index].checked = false; //改变当前选中的checked值 取消选择
      } else {
        recuitType[index].checked = true; //改变当前选中的checked值 确认选择
      }

      this.setData({
        recuitType: recuitType,
        other_flag: false,
      })
    }

    console.log("id+" + this.data.type_id)

  },


  indexOf: function(arr, val) {
    for (var i = 0; i < arr.length; i++) {
      if (arr[i] == val) return i;
    }
    return -1;
  },

  remove: function(arr, val) {
    var index = arr.indexOf(val);
    if (index > -1) {
      arr.splice(index, 1);
    }
  },
  click_status() {
    this.setData({
      recuitStatus_flag: false,
    })
  },
  //主播类型
  click_type() {
    let that = this;
    that.setData({
      type_flag: false,
      type_id: [],
      type_name: ''
    })
    this.recuitType_info();
  },
  //关闭弹框
  modal_hide() {
    this.setData({
      platform_flag: true,
      type_flag: true,
      recuitStatus_flag: true,
      upload_fail: true,
      upload_ok: true,
    })
  },
  //input 输入框
  inp_name: function(e) {
    // console.log(e.detail.value)
    this.setData({
      name_value: e.detail.value,
    })
  },
  inp_phone: function(e) {
    let that = this;
    that.setData({
      phone_value: e.detail.value,
    })
    // console.log(e.detail.value)

    let str = e.detail.value;
    let reg = /^1[3|4|5|7|8|9][0-9]{9}$/;
    let flag = reg.test(str);
    console.log(flag)
    if (flag) {
      that.setData({
        reg_true: true,
        phone_value: e.detail.value,
      })
    }
  },

  //选择 裁剪图片
  click_close: function() {
    this.setData({
      tailor_show: true,
    })
  },
  touchStart(e) {
    this.wecropper.touchStart(e)
  },
  touchMove(e) {
    this.wecropper.touchMove(e)
  },
  touchEnd(e) {
    this.wecropper.touchEnd(e)
  },
  getCropperImage() {
    wx.showLoading({
      title: '加载中~',
      icon: "none",
    })
    let that = this;
    this.wecropper.getCropperImage((src) => {
      if (src) {
        // console.log('图片+'+src)
        var image_base64 = wx.getFileSystemManager().readFileSync(src, "base64");
        if (that.data.resume_id) {
          var resume_id = that.data.resume_id;
        } else {
          var resume_id = 0;
        }
        // console.log('imgOne+' + that.data.one_base64)
        // console.log('imgTwo+' + that.data.two_base64)
        // console.log('imgThree+' + that.data.three_base64)
        if (that.data.imgOne) {
          //发送请求
          that.setData({
            one_url: src,
            one_base64: image_base64 + '',
            tailor_show: true,
          })
          wx.hideLoading();
        } else if (that.data.imgTwo) {
          //发送请求
          that.setData({
            two_url: src,
            two_base64: image_base64 + '',
            tailor_show: true,
          })
          wx.hideLoading();
        } else if (that.data.imgThree) {
          //发送请求
          that.setData({
            three_url: src,
            three_base64: image_base64 + '',
            tailor_show: true,
          })
          wx.hideLoading();
        } else {}
      } else {
        console.log('获取图片地址失败，请稍后重试')
      }

    });
  },
  //选择图片
  click_imgOne: function(e) {
    let that = this,
      num = e.currentTarget.dataset.num;
    this.init();
    that.setData({
      tailor_show: false,

      imgOne: true,
      imgTwo: false,
      imgThree: false,
    })
    this.fix_phone()
  },
  click_imgTwo: function(e) {
    if (this.data.one_base64 || this.data.one_url) {
      let that = this,
        num = e.currentTarget.dataset.num;
      this.init();
      this.setData({
        tailor_show: false,

        imgOne: false,
        imgTwo: true,
        imgThree: false,
      })
      this.fix_phone()
    } else {
      wx.showToast({
        title: '请先上传前一个',
        icon: 'none'
      })
    }

  },
  click_imgThree: function(e) {
    if ((this.data.one_base64 || this.data.one_url) && (this.data.two_base64 || this.data.two_url)) {
      let that = this,
        num = e.currentTarget.dataset.num;
      this.init();
      this.setData({
        tailor_show: false,

        imgOne: false,
        imgTwo: false,
        imgThree: true,
      })
      this.fix_phone()
    } else {
      wx.showToast({
        title: '请先上传前一个',
        icon: 'none'
      })
    }

  },
  uploadTap() {
    const self = this;
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      // sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
      // sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      sourceType: ['album'], // 可以指定来源是相册还是相机，默认二者都有
      success(res) {
        const src = res.tempFilePaths[0]
        //  获取裁剪图片资源后，给data添加src属性及其值
        self.wecropper.pushOrign(src)
      }
    })
  },
  //裁剪图片 初始化
  init: function() {
    const {
      cropperOpt
    } = this.data

    new WeCropper(cropperOpt)
      .on('ready', (ctx) => {
        // console.log(`wecropper is ready for work!`)
      })
      .on('beforeImageLoad', (ctx) => {
        // console.log(`before picture loaded, i can do something`)
        // console.log(`current canvas context:`, ctx)
        wx.showToast({
          title: '上传中',
          icon: 'loading',
          duration: 20000
        })
      })
      .on('imageLoad', (ctx) => {
        // console.log(`picture loaded`)
        // console.log(`current canvas context:`, ctx)
        wx.hideToast()
      })
      .on('beforeDraw', (ctx, instance) => {
        // console.log(`before canvas draw,i can do something`)
        // console.log(`current canvas context:`, ctx)
      })
      .updateCanvas()
  },






  //sex
  click_girl: function() {
    this.setData({
      girl: true,
      man: false,
      sex: 2,
    })
  },
  click_man: function() {
    this.setData({
      girl: false,
      man: true,
      sex: 1,
    })
  },
  //选择 picker
  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    let date = new Date();
    let dateStr = e.detail.value;
    var time_str = Date.parse(dateStr) / 1000;
    // console.log(time_str)
    this.jsGetAge(dateStr)
    this.setData({
      date: time_str
    })
    // console.log(this.data.date)
  },
  //计算年岁
  jsGetAge: function(strBirthday) {
    var returnAge;
    var strBirthdayArr = strBirthday.split("-");
    var birthYear = strBirthdayArr[0];
    var birthMonth = strBirthdayArr[1];
    var birthDay = strBirthdayArr[2];

    var d = new Date();
    var nowYear = d.getFullYear();
    var nowMonth = d.getMonth() + 1;
    var nowDay = d.getDate();

    if (nowYear == birthYear) {
      returnAge = 0; //同年 则为0岁  
    } else {
      var ageDiff = nowYear - birthYear; //年之差  
      if (ageDiff > 0) {
        if (nowMonth == birthMonth) {
          var dayDiff = nowDay - birthDay; //日之差  
          if (dayDiff < 0) {
            returnAge = ageDiff - 1;
          } else {
            returnAge = ageDiff;
          }
        } else {
          var monthDiff = nowMonth - birthMonth; //月之差  
          if (monthDiff < 0) {
            returnAge = ageDiff - 1;
          } else {
            returnAge = ageDiff;
          }
        }
      } else {
        returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
      }
    }
    if (returnAge == "-1") {
      wx.showToast({
        title: '年龄输入有误',
        icon: "none",
      });
      this.setData({
        age: '',
      })
    } else {
      this.setData({
        age: returnAge,
      })
    }
    return returnAge; //返回周岁年龄  

  },

  //判断手机号
  fix_phone: function() {
    let that = this;

    let phone_num = that.data.phone_value;
    let reg = /^1[3|4|5|7|8|9][0-9]{9}$/;
    let flag = reg.test(phone_num);
    console.log(flag)
    if (flag) {
      that.setData({
        reg_true: true,
      })
    }
  },
  click_pause() {
    this.setData({
      upload_fail: false,
    })
  },
  //click_bianji
  click_bianji: function(e) {
    console.log(e)
    this.setData({
      is_resume: '0',
      bianji_flag: '1',
      reg_true: false,
    })
    // console.log('flag+'+this.data.bianji_flag)
  },
  //提交
  click_submit: function() {
    let that = this;
    wx.showLoading({
      title: '上传中',
      mask: true,
    })
    this.getInfo();
    that.fix_phone();
    if (that.data.resume.has_resume == "0") {
      console.log("没有简历")
      // 没有简历
      // if (that.data.one_base64 || that.data.two_base64 || that.data.three_base64) {
      if (that.data.one_base64) {
        // 图片
        if (that.data.name_value && that.data.sex && that.data.age && that.data.phone_value && that.data.live_age && that.data.type_name && that.data.wanted_status) {
          if (that.data.reg_true) {
            if (typeof(that.data.type_id) == "string") {
              var anchor_type = that.data.type_id;
            } else {
              var anchor_type = that.data.type_id.join(",");
            }
            //基本简历信息
            var one_base64 = that.data.one_base64,
              two_base64 = that.data.two_base64,
              three_base64 = that.data.three_base64,
              one_url = that.data.one_url,
              two_url = that.data.two_url,
              three_url = that.data.three_url;
            if (one_base64) {
              var resume_photo = [{
                "place": 1,
                "img_url": one_base64
              }]
            } else if (one_base64 && two_base64) {
              var resume_photo = [{
                  "place": 1,
                  "img_url": one_base64
                },
                {
                  "place": 2,
                  "img_url": two_base64
                }
              ]
            } else if (one_base64 && two_base64 && three_base64) {
              var resume_photo = [{
                  "place": 1,
                  "img_url": one_base64
                },
                {
                  "place": 2,
                  "img_url": two_base64
                },
                {
                  "place": 3,
                  "img_url": three_base64
                }
              ]
            }
            console.log('resume_photo2+' + resume_photo)
            var datalist = JSON.stringify(resume_photo);
            wx.request({
              url: app.globalData.url + 'api/resume/new/add',
              method: 'POST',
              data: {
                token: app.globalData.token,
                nickname: that.data.name_value,
                sex: that.data.sex,
                age: that.data.age,
                telephone: that.data.phone_value,
                date_of_birth: that.data.date,
                anchor_type: anchor_type,
                height: that.data.height,
                weight: that.data.weight,
                live_age: that.data.live_age,
                pay_low: that.data.pay_low,
                pay_high: that.data.pay_high,
                per_style: that.data.per_style,
                is_open: that.data.is_open,
                resume_photo: datalist,
                wanted_status: that.data.wanted_status,
              },
              success: function(e) {
                // console.log(e)
                if (that.data.flag_first) {
                  console.log('flag_first=' + that.data.flag_first)
                  that.setData({
                    upload_ok: false
                  })
                }
                wx.hideLoading()
                wx.showToast({
                  title: '保存成功,等待c位出道~',
                  icon: 'none',
                })
                if (that.data.detail == '1') {
                  wx.hideLoading()
                  wx.navigateBack({
                    delta: 1,
                  })
                } else if (that.data.welfare) {
                  wx.hideLoading()
                  wx.navigateBack({
                    delta: 1,
                  })
                } else {
                  wx.hideLoading()
                  wx.navigateBack({
                    delta: 1,
                  })
                }
                // if (that.data.flag_first) {
                //   wx.redirectTo({
                //     url: '../../recruit/index/index?flag_first=true'
                //   })
                // }
              }
            })
            // that.resumeLoad();
          } else {
            wx.showToast({
              title: '手机号格式有误~',
              icon: 'none',
            })
          }

        } else {
          wx.showToast({
            title: '请注意信息完整~~',
            icon: 'none',
          })
        }
      } else {
        wx.showToast({
          title: '第一张不能为空~',
          icon: 'none',
        })
      }
    } else {
      console.log("有简历>修改")
      // 有简历
      // that.setData({
      //   reg_true: true,
      // })
      if (that.data.name_value && that.data.sex && that.data.age && that.data.phone_value && that.data.live_age && that.data.type_name && that.data.wanted_status) {

        if (that.data.reg_true) {
          // console.log("有简历")
          if (typeof(that.data.type_id) == "string") {
            var anchor_type = that.data.type_id;
          } else {
            var anchor_type = that.data.type_id.join(",");
          }
          //基本简历信息
          var one_base64 = that.data.one_base64,
            two_base64 = that.data.two_base64,
            three_base64 = that.data.three_base64,
            one_url = that.data.one_url,
            two_url = that.data.two_url,
            three_url = that.data.three_url;
          if (one_base64 && (!two_url && !two_base64) && (!three_url && !three_base64)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_base64
            }]
          } else if (one_base64 && two_base64 && (!three_base64 && !three_url)) {
            var resume_photo = [{
                "place": 1,
                "img_url": one_base64
              },
              {
                "place": 2,
                "img_url": two_base64
              }
            ]
          } else if (one_base64 && two_base64 && three_base64) {
            var resume_photo = [{
                "place": 1,
                "img_url": one_base64
              },
              {
                "place": 2,
                "img_url": two_base64
              },
              {
                "place": 3,
                "img_url": three_base64
              }
            ]
          } else if ((one_url && !one_base64) && (!two_url && !two_base64) && (!three_url && !three_base64)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }]
          } else if ((one_url && !one_base64) && (two_url && !two_base64) && (!three_base64 && !three_url)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": two_url
            }]
          } else if ((one_url && !one_base64) && (two_url && !two_base64) && (three_url && !three_base64)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": two_base64
            }, {
              "place": 3,
              "img_url": three_base64
            }]
          } else if ((one_url && !one_base64) && (two_url && !two_base64) && (!three_url && !three_base64)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": two_url
            }]
          } else if ((one_url && !one_base64) && (two_url && two_base64) && (three_url && three_base64)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": two_base64
            }, {
              "place": 3,
              "img_url": three_base64
            }]
          } else if ((one_url && !one_base64) && (two_url && two_base64) && (three_url && !three_base64)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": two_base64
            }, {
              "place": 3,
              "img_url": three_url
            }]
          } else if ((one_url && !one_base64) && (two_url && !two_base64) && (three_url && three_base64)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": two_url
            }, {
              "place": 3,
                "img_url": three_base64
            }]
          } else if (one_base64 && (two_url && !two_base64) && (!three_base64 && !three_url)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_base64
            }, {
              "place": 2,
              "img_url": two_url
            }]
          } else if (one_base64 && two_base64 && (three_url && !three_base64)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_base64
            }, {
              "place": 2,
              "img_url": two_base64
            }, {
              "place": 3,
              "img_url": three_url
            }]
          } else if (one_base64 && (two_url && !two_base64) && three_base64) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_base64
            }, {
              "place": 2,
              "img_url": two_url
            }, {
              "place": 3,
              "img_url": three_base64
            }]
          } else if (one_base64 && (two_url && !two_base64) && (three_url && !three_base64)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_base64
            }, {
              "place": 2,
              "img_url": two_url
            }, {
              "place": 3,
              "img_url": three_url
            }]
          } else if ((one_url && !one_base64) && two_base64 && (!three_base64 && !three_url)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": two_base64
            }]
          } else if ((one_url && !one_base64) && two_base64 && three_base64) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": two_base64
            }, {
              "place": 3,
              "img_url": three_base64
            }]
          } else if ((one_url && !one_base64) && two_base64 && (three_url && !three_base64)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": two_base64
            }, {
              "place": 3,
              "img_url": three_url
            }]
          } else if ((one_url && !one_base64) && (two_url && !two_base64) && three_base64) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": two_url
            }, {
              "place": 3,
              "img_url": three_base64
            }]
          } else if ((one_url && !one_base64) && three_base64 && (!two_base64 && !two_url)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": three_base64
            }]
          } else if ((one_url && !one_base64) && (three_url && !three_base64) && (!two_url && !two_base64)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": three_url
            }]
          } else if (one_base64 && three_base64 && (!two_base64 && !two_url)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_base64
            }, {
              "place": 2,
              "img_url": three_base64
            }]
          } else if ((one_url && !one_base64) && two_base64 && (!three_base64 && !three_url)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_url
            }, {
              "place": 2,
              "img_url": two_base64
            }]
          } else if (one_base64 && (three_url && !three_base64) && (!two_base64 && !two_url)) {
            var resume_photo = [{
              "place": 1,
              "img_url": one_base64
            }, {
              "place": 2,
              "img_url": three_url
            }]
          } else {
            wx.showToast({
              title: '请删除所有照片，依次上传哦',
              icon: 'none'
            })
          }
          console.log(resume_photo);
          var datalist = JSON.stringify(resume_photo);
          wx.request({
            url: app.globalData.url + 'api/resume/new/update',
            method: 'POST',
            data: {
              token: app.globalData.token,
              resume_id: that.data.resume_id,
              nickname: that.data.name_value,
              sex: that.data.sex,
              age: that.data.age,
              telephone: that.data.phone_value,
              date_of_birth: that.data.date,
              anchor_type: anchor_type,
              height: that.data.stature,
              weight: that.data.weight,
              live_age: that.data.live_age,
              pay_low: that.data.pay_low,
              pay_high: that.data.pay_high,
              per_style: that.data.per_style,
              is_open: that.data.is_open,
              resume_photo: datalist,
              wanted_status: that.data.wanted_status,
            },
            success: function(e) {
              // console.log(e)
              if (that.data.flag_first) {
                upload_fail: false
              }
              wx.showToast({
                title: '保存成功,等待c位出道~',
                icon: 'none',
              })
              //请求图片
              wx.request({
                url: app.globalData.url + 'api/resume/read/photo',
                method: 'POST',
                data: {
                  token: app.globalData.token,
                },
                success: function(e) {
                  // console.log(e)
                  wx.hideLoading()
                  let imageOne = (e.data.data.resume["0"]) ? e.data.data.resume["0"].img_url : '',
                    imageTwo = (e.data.data.resume["1"]) ? e.data.data.resume["1"].img_url : '',
                    imageThree = (e.data.data.resume["2"]) ? e.data.data.resume["2"].img_url : '';
                  that.setData({
                    imageOne: imageOne,
                    imageTwo: imageTwo,
                    imageThree: imageThree,
                  })
                  //身份切换后 可能出错点
                  that.resumeLoad();
                  wx.navigateBack({
                    delta: 1,
                  })
                }
              })
              that.setData({
                is_resume: '1',
              })
              that.resumeLoad();

            }
          })
        } else {
          wx.showToast({
            title: '手机号格式有误~',
            icon: 'none',
          })
        }
      } else {
        wx.showToast({
          title: '请注意信息完整~~',
          icon: 'none',
        })
      }
    }

  },
  //获得状态信息
  getStatus() {
    wx.request({
      url: app.globalData.url + 'api/resume/wanted/status',
      data: {
        token: app.globalData.token
      },
      method: 'POST',
      success: (e) => {
        console.log(e);
        let recuitStatus = e.data.data.list;
        recuitStatus.forEach(item => {
          item.checked = false
        })
        this.setData({
          recuitStatus: recuitStatus,
        })
      }
    })
  },
  //获得个人信息
  getInfo() {
    wx.request({
      url: app.globalData.url + 'api/invitation/my/balance',
      data: {
        token: app.globalData.token
      },
      method: 'POST',
      success: (e) => {
        // console.log(e)
        let resume = e.data.data;
        console.log(e)
        this.setData({
          resume: resume,
        })
      },
    })
  },
  //请求简历
  resumeLoad: function() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/resume/index',
      method: 'POST',
      data: {
        token: app.globalData.token,
      },
      success: function(e) {
        console.log(e)
        if (!e.data.data.resume.nickname) {
          //为空
        } else {
          //不为空
          let salaryRange_text = e.data.data.resume.pay_low + "-" + e.data.data.resume.pay_high;
          that.setData({
            resume: e.data.data.resume,
            name_value: e.data.data.resume.nickname,
            sex: e.data.data.resume.sex,
            age: e.data.data.resume.age,
            phone_value: e.data.data.resume.telephone,
            date: e.data.data.resume.date_of_birth,

            status_name: e.data.data.resume.wanted_status_name,
            wanted_status: e.data.data.resume.wanted_status,

            resume_id: e.data.data.resume.id,
            // resume_id: e.data.data.resume.id, e.data.resume.id
            //个人风采
            type_id: e.data.data.resume.anchor_type, //职位id
            type_name: e.data.data.resume.type_name.join(","), //职位类型

            stature: e.data.data.resume.height,
            weight: e.data.data.resume.weight,
            live_age: e.data.data.resume.live_age,
            per_style: e.data.data.resume.per_style,

            pay_low: e.data.data.resume.pay_low,
            pay_high: e.data.data.resume.pay_high,
            salaryRange_text: salaryRange_text,


            card_show: false,
          })
          if (that.data.sex == '1') {
            that.setData({
              man: true,
            })
          } else if (that.data.sex == '2') {
            that.setData({
              girl: true,
            })
          } else {}
          wx.setNavigationBarTitle({
            title: "我的简历" //页面标题为路由参数
          })
          //请求图片
          wx.request({
            url: app.globalData.url + 'api/resume/read/photo',
            method: 'POST',
            data: {
              token: app.globalData.token,
            },
            success: function(e) {
              // console.log(e)
              let imageOne = e.data.data.resume["0"] ? e.data.data.resume["0"].img_url : "",
                imageTwo = e.data.data.resume[1] ? e.data.data.resume[1].img_url : "",
                imageThree = e.data.data.resume[2] ? e.data.data.resume[2].img_url : "",
                one_url = e.data.data.resume["0"] ? e.data.data.resume["0"].img_url : "",
                two_url = e.data.data.resume[1] ? e.data.data.resume[1].img_url : "",
                three_url = e.data.data.resume[2] ? e.data.data.resume[2].img_url : "";

              that.setData({
                imageOne: imageOne,
                imageTwo: imageTwo,
                imageThree: imageThree,

                one_url: one_url,
                two_url: two_url,
                three_url: three_url,
              })
            }
          })

        }

      }
    })
  },
  //获取职位类型
  recuitType_info() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/recruit/platfrom/type',
      data: {
        token: app.globalData.token,
      },
      method: 'POST',
      success: function(e) {
        // console.log(e.data.data.recuitType);

        //直播类型
        let recuitType_new = e.data.data.recuitType;
        let recuitType = [];
        recuitType_new.map(((item, index) => {
          recuitType.push(Object.assign(item, {
            checked: false
          }))
        }))
        that.setData({
          recuitType: recuitType,
        })
      },
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this;
    this.init();
    this.getInfo();
    this.click_bianji();
    this.getStatus();
    this.setData({
      phone_value: app.register_info.telephone,
    })
    // this.resumeLoad()
    if (options.welfare) {
      this.setData({
        welfare: true
      })
    }
    if (options.detail) {
      this.setData({
        detail: options.detail,
      })
    }
    if (options.flag_first) {
      this.setData({
        flag_skip: true,
        flag_first: true,
      })
    }
    // 进入判断是否存在简历
    wx.request({
      url: app.globalData.url + 'api/recruit/list',
      method: 'POST',
      data: {
        token: app.globalData.token,
      },
      success: function(e) {
        console.log(e.data.data.is_resume)
        that.setData({
          //是否存在
          is_resume: e.data.data.is_resume
        })
        if (e.data.data.is_resume == '1') {
          //请求简历数据
          that.resumeLoad()
        }
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    this.setData({
      phone_value: wx.getStorageSync('reg_telephone')
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this;
    this.getInfo();
    this.recuitType_info();
    this.get_salary();
    this.get_stature();
    this.get_weight();
    this.get_live_age();
    // this.resumeLoad();

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})